home *** CD-ROM | disk | FTP | other *** search
- { This project accompanies the second article written by Alan Moore
- and Ken Kyler on TAPI }
-
- unit Tapiu_2;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls, Mask, ComCtrls, Buttons, CommStatus, Tapi;
-
- type
- TForm1 = class(TForm)
- PanelTop: TPanel;
- Label1: TLabel;
- ePhoneNum: TMaskEdit;
- btnDial: TButton;
- btnHangup: TButton;
- cboxDevices: TComboBox;
- cbLineMapper: TCheckBox;
- Memo: TMemo;
- StatusBar: TPanel;
- ImageList: TImageList;
- cboxMediaMode: TComboBox;
- cboxBearerMode: TComboBox;
- Panel1: TPanel;
- RI: TImage;
- CD: TImage;
- RD: TImage;
- DSR: TImage;
- DTR: TImage;
- CTS: TImage;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Label7: TLabel;
- Port: TImage;
- Label8: TLabel;
- btnDialingProperties: TButton;
- procedure btnDialClick(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure FormCreate(Sender: TObject);
- procedure btnHangupClick(Sender: TObject);
- procedure cboxDevicesChange(Sender: TObject);
- procedure cbLineMapperClick(Sender: TObject);
- procedure cboxMediaModeChange(Sender: TObject);
- procedure cboxBearerModeChange(Sender: TObject);
- procedure btnDialingPropertiesClick(Sender: TObject);
- private
- { Private declarations }
- FCommStatusThread: TCommStatus;
- FTapiInitialized : Boolean;
- function TapiInitialize: boolean;
- procedure CreateCallManager;
- // really a bad description! The whole application is the call manager
- procedure EnumerateDevices;
- // added 11 Jan 98
- //=========================================================
- procedure ModemOff;
- function GetPortHandle : THandle;
- // added by Alan 6 April 98
- procedure ShowLineTranslateDialog(Sender: TObject);
- // =====================================================================
-
- public
- { Public declarations }
- { Because ShutdownCallManager is called from the CallBack function,
- ShutdownCallManager must be declared public }
- function ShutdownCallManager: boolean;
- procedure SetBitmap(Image: TImage; Index: integer);
- end;
-
- var
- Form1: TForm1;
- FLineApp: HLINEAPP;
- FNumDevs,
- FVersion: Integer;
- FMediaMode,
- FBearerMode: DWord;
- FExt: TLINEEXTENSIONID;
- FLine: HLINE;
- FLineCallParams: TLineCallParams;
- FLineOpen: boolean;
- FHCall: HCALL;
- FCountryCode: integer;
- FDev: integer; //value of device ID to initialize, 0..NumDevs }
- FPort: THandle; // handle of the opened port - new 18 Jan 98
- FCanonicalPhNum : LPCSTR; // canonical phone number - 23 April 1998
- FLineTranslateOptions : DWord;
- lpTranslateOutput : LPLINETRANSLATEOUTPUT;
-
- implementation
-
- {$R *.DFM}
-
- const
- Ver = $00010004; // API version accepted (1.4) [Windows 95]
- off = 0;
- red = 1;
- yellow = 2;
- green = 3;
-
- // Local Functions -------------------------------------------------------------
- procedure LineCallBack(hDevice, dwMessage, dwInstance, dwParam1, dwParam2,
- dwParam3 : DWORD); stdcall; // handles messages from the line
- begin
- with Form1, Memo.Lines do begin
- case dwMessage of
- LINE_CALLSTATE: begin //reports asynchronous responses
- case dwParam1 of
- LINECALLSTATE_IDLE: begin
- Add('LCB (LINE_CALLSTATE): The call is idle - ' +
- ' no call actually exists.');
- ShutdownCallManager;
- end;
- LINECALLSTATE_OFFERING:
- Add('LCB (LINE_CALLSTATE): ' +
- ' The call is being offered to the station.');
- LINECALLSTATE_ACCEPTED:
- Add('LCB (LINE_CALLSTATE): ' +
- ' The call was offering and has been accepted.');
- LINECALLSTATE_DIALTONE: begin
- // added 14 Jan 98 ============================================
- ImageList.GetBitMap(green, CD.Picture.Bitmap);
- // ============================================================
- Add('LCB (LINE_CALLSTATE): The call is receiving a dial tone.');
- end;
- LINECALLSTATE_DIALING:
- Add('LCB (LINE_CALLSTATE): Dialing ' + Form1.ePhoneNum.Text);
- LINECALLSTATE_RINGBACK:
- Add('LCB (LINE_CALLSTATE): The call is receiving ringback.');
- LINECALLSTATE_BUSY: begin // note, difficult to detect
- case dwParam2 of
- LINEBUSYMODE_STATION:
- Add('LCB (LINE_CALLSTATE): ' +
- 'Busy signal; called party''s station is busy.');
- LINEBUSYMODE_TRUNK:
- Add('LCB (LINE_CALLSTATE): ' +
- 'Busy signal; trunk or circuit is busy.');
- LINEBUSYMODE_UNKNOWN:
- Add('LCB (LINE_CALLSTATE): ' +
- ' Busy signal; specific mode is currently unkown');
- LINEBUSYMODE_UNAVAIL:
- Add('LCB (LINE_CALLSTATE): ' +
- ' Busy signal; specific mode is unavailable');
- else
- Add('LCB (LINE_CALLSTATE): ' +
- ' The call is receiving an unidentifiable busy tone.');
- end;
- ShutdownCallManager;
- end;
- LINECALLSTATE_SPECIALINFO:
- Add('LCB (LINE_CALLSTATE): ' +
- ' Special information is sent by the network.');
- LINECALLSTATE_CONNECTED:
- Add('LCB (LINE_CALLSTATE): ' +
- ' The call has been established and the connection is made.');
- LINECALLSTATE_PROCEEDING:
- Add('LCB (LINE_CALLSTATE): ' +
- ' Dialing has completed and the call is proceeding.');
- LINECALLSTATE_ONHOLD:
- Add('LCB (LINE_CALLSTATE): The call is on hold by the switch.');
- LINECALLSTATE_CONFERENCED:
- Add('LCB (LINE_CALLSTATE): The call is currently ' +
- ' a member of a multi-party conference call.');
- LINECALLSTATE_ONHOLDPENDCONF:
- Add('LCB (LINE_CALLSTATE): The call is currently ' +
- ' on hold while it is being added to a conference.');
- LINECALLSTATE_DISCONNECTED: begin
- Add('LCB (LINE_CALLSTATE): The line has been disconnected.');
- case dwParam2 of
- LINEDISCONNECTMODE_NORMAL:
- Add(#9 + 'This is a "normal" disconnect request.');
- LINEDISCONNECTMODE_UNKNOWN:
- Add(#9 + 'The reason for the disconnect ' +
- ' request is unknown.');
- LINEDISCONNECTMODE_REJECT:
- Add(#9 + 'The remote user has rejected the call.');
- LINEDISCONNECTMODE_PICKUP:
- Add(#9 + 'The call was picked up from elsewhere.');
- LINEDISCONNECTMODE_FORWARDED:
- Add(#9 + 'The call was forwarded by the switch.');
- LINEDISCONNECTMODE_BUSY:
- Add(#9 + 'The remote user''s station is busy.');
- LINEDISCONNECTMODE_NOANSWER:
- Add(#9 + 'The remote user''s station does not answer.');
- LINEDISCONNECTMODE_BADADDRESS:
- Add(#9 + 'The destination address in invalid.');
- LINEDISCONNECTMODE_UNREACHABLE:
- Add(#9 + 'The remote user could not be reached.');
- LINEDISCONNECTMODE_CONGESTION:
- Add(#9 + 'The network is congested.');
- LINEDISCONNECTMODE_INCOMPATIBLE:
- Add(#9 + 'The remote user''s station equipment ' +
- ' is incompatible');
- LINEDISCONNECTMODE_UNAVAIL:
- Add(#9 + 'The reason for the disconnect is unavailable');
- end;
- end;
- LINECALLSTATE_UNKNOWN:
- Add('LCB (LINE_CALLSTATE): The state of the call is not known.');
- end;
- end;
- LINE_LINEDEVSTATE:
- case dwParam1 of // incomplete list
- LINEDEVSTATE_RINGING:
- Add('LCB (LINE_LINEDEVSTATE): (Ringing) Ring, ring, ring...');
- LINEDEVSTATE_CONNECTED:
- Add('LCB (LINE_LINEDEVSTATE): Connected...');
- LINEDEVSTATE_DISCONNECTED:
- Add('LCB (LINE_LINEDEVSTATE): Disconnected.');
- LINEDEVSTATE_REINIT: // line device has changed or been modified
- if (dwParam2 = 0) then begin
- Add('LCB (LINE_LINEDEVSTATE): Shutdown required');
- ShutdownCallManager;
- end;
- end;
- LINE_REPLY:
- if (dwParam2 = 0) then begin
- Add('LCB (LINE_REPLY): LineMakeCall completed successfully');
- SetBitMap(DTR, green);
- end
- else
- Add('LCB (LINE_REPLY): LineMakeCall failed');
- end;
- end;
- end;
-
- function RecordGetStr (var Data; Field : Pointer) : string;
- var
- Len: Longint;
- begin
- Len := PInt(Field)^; // PInt is defined in Windows.pas
- Inc(PInt(Field));
- if (PInt(Field)^ <> 0) then
- SetString(Result, PChar(Longint(@Data) + PInt(Field)^), Len - 1)
- else
- Result := '';
- end;
- //-- End of Local Functions ----------------------------------------------------
-
- procedure TForm1.btnDialClick(Sender: TObject);
- begin
- if not cbLineMapper.Checked and (FDev < 0) then begin // a device wasn't selected
- ShowMessage('You must first select a Line device!');
- Exit;
- end;
- btnDial.Enabled := false; // disable the dial button
- btnHangup.Enabled := true; // and enable the hangup button
- CreateCallManager;
- // 14 Jan 98 - changed to line make call
- end;
-
- procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- // if the custom call manager was used, make sure to free resources
- if FLineOpen then
- CanClose := ShutdownCallManager;
- end;
-
- function TForm1.TapiInitialize: boolean;
- var
- ErrNo: Longint;
- S: string;
- begin
- Result := false;
- // Initialize TAPI for use by custom call manager
- FCountryCode := 0;
- FVersion := 0;
- ErrNo := LineInitialize(@FLineApp, MainInstance, LineCallback, '', @FNumDevs);
- case ErrNo of
- 0: Begin
- Memo.Lines.Add('LineInitialize was successful');
- FTapiInitialized := true;
- end;
- LINEERR_INVALAPPNAME: S := 'LINEERR_INVALAPPNAME';
- LINEERR_OPERATIONFAILED: S := 'LINEERR_OPERATIONFAILED';
- LINEERR_INIFILECORRUPT: S := 'LINEERR_INIFILECORRUPT';
- LINEERR_RESOURCEUNAVAIL: S := 'LINEERR_RESOURCEUNAVAIL';
- LINEERR_INVALPOINTER: S := 'LINEERR_INVALPOINTER';
- LINEERR_REINIT: S := 'LINEERR_REINIT - (try again)';
- LINEERR_NODRIVER: S := 'LINEERR_NODRIVER';
- LINEERR_NODEVICE: S := 'LINEERR_NODEVICE';
- LINEERR_NOMEM: S := 'LINEERR_NOMEM';
- LINEERR_NOMULTIPLEINSTANCE: S := 'LINEERR_NOMULTIPLEINSTANCE';
- else
- S := 'Unknown Reason (' + IntToStr(ErrNo) + ')';
- end;
-
- // show how many devices available
- Memo.Lines.Add('Devices available: ' + IntToStr(FNumDevs));
-
- if (ErrNo <> 0) then begin
- Memo.Lines.Add('LineInitialize failed with error: ' + S);
- Exit;
- end
- else
- ErrNo := LineNegotiateAPIVersion(FLineApp, FDev, Ver, Ver,
- @FVersion, @FExt);
- if (ErrNo <> 0) then begin
- case ErrNo of
- LINEERR_BADDEVICEID: S := 'LINEERR_BADDEVICEID';
- LINEERR_NODRIVER: S := 'LINEERR_NODRIVER';
- LINEERR_INCOMPATIBLEAPIVERSION: S :=
- 'LINEERR_INCOMPATIBLEAPIVERSION';
- LINEERR_OPERATIONFAILED: S := 'LINEERR_OPERATIONFAILED';
- LINEERR_INVALAPPHANDLE: S := 'LINEERR_INVALAPPHANDLE';
- LINEERR_RESOURCEUNAVAIL: S := 'LINEERR_RESOURCEUNAVAIL';
- LINEERR_INVALPOINTER: S := 'LINEERR_INVALPOINTER';
- LINEERR_UNINITIALIZED: S := 'LINEERR_UNINITIALIZED';
- LINEERR_NOMEM: S := 'LINEERR_NOMEM';
- LINEERR_OPERATIONUNAVAIL: S := 'LINEERR_OPERATIONUNAVAIL';
- LINEERR_NODEVICE: S := 'LINEERR_NODEVICE';
- else
- S := 'Unknown Reason (' + IntToStr(ErrNo) + ')';
- end;
- LineShutDown(FLineApp);
- Memo.Lines.Add('LineNegotiateAPIVersion failed with error: ' + S);
- end
- else begin
- FDev := cboxDevices.ItemIndex; // synch FDev with the combobox
- Result := true;
- end;
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- var
- S: string;
- begin
- // added by Alan 23 Jan 98
- ImageList := TImageList.Create(Application);
- // added 11 Jan 98
- // ===========================================================
- S := ExtractFilePath(Application.exename);
- // Added by Alan April 19, 1998
- FTapiInitialized := false;
- // FCommStatusThread.Create(true);
- // Above Changed by Alan, 23 Jan 98
- FCommStatusThread := TCommStatus.Create(true); // create thread suspended
- // load the ImageList
- with ImageList do begin
- FileLoad(rtBitMap, S + 'LEDOff.bmp', clNone); // 0
- FileLoad(rtBitMap, S + 'LEDRedOn.bmp', clNone); // 1
- FileLoad(rtBitMap, S + 'LEDYellowOn.bmp', clNone); // 2
- FileLoad(rtBitMap, S + 'LEDGreenOn.bmp', clNone); // 3
- end;
- with ImageList do begin
- GetBitMap(off, RI.Picture.Bitmap);
- GetBitMap(off, CD.Picture.Bitmap);
- GetBitMap(off, RD.Picture.Bitmap);
- GetBitMap(off, DSR.Picture.Bitmap);
- GetBitMap(off, DTR.Picture.Bitmap);
- GetBitMap(off, CTS.Picture.Bitmap);
- GetBitMap(off, Port.Picture.Bitmap);
- end;
- FMediaMode := LINEMEDIAMODE_DATAMODEM;
- FBearerMode := LINEBEARERMODE_VOICE; /// changed from speech
- cboxMediaMode.ItemIndex := 3; // default to LINEMEDIAMODE_DATAMODEM
- cboxBearerMode.ItemIndex := 0; // default to LINEBEARERMODE_VOICE
- // ===========================================================================
- FDev := 0; // default device
- FLineOpen := false;
- btnHangup.Enabled := false; // disable the hangup button
- if not TapiInitialize then begin
- Memo.Clear;
- Memo.Lines.Add('Failed to initialize TAPI');
- btnHangup.Enabled := false; // disable the hangup button
- btnDial.Enabled := false; // disable the dial button
- end
- else begin
- { fill the LineCallParams structure with default values.
- Mandatory for data calls, optional for voice calls }
- with FLineCallParams do begin
- dwTotalSize := sizeof(FLineCallParams);
- dwBearerMode := FBearerMode;;
- dwMediaMode := FMediaMode;
- end;
- // fill the combobox with the available devices
- EnumerateDevices;
- StatusBar.Caption := cboxDevices.Text;
- end;
- end;
-
- procedure TForm1.btnHangupClick(Sender: TObject);
- begin
- if not ShutdownCallManager then
- Exit;
- end;
-
- procedure TForm1.CreateCallManager;
- var
- S: string;
- ErrNo: longint;
- begin
- Memo.Clear;
- if not FLineOpen then // if a line is open, no need to initialize TAPI
- if not TapiInitialize then begin
- Memo.Lines.Add('Failed to initialize TAPI');
- Exit;
- end;
-
- // open a line and get the line handle
- if cbLineMapper.Checked then // automatically select the device
- ErrNo := LineOpen(FLineApp, LINEMAPPER, @FLine, FVersion, 0, 0,
- LINECALLPRIVILEGE_NONE, FMediaMode, @FLineCallParams)
- // added FMediaMode 14 Jan 98
- else
- ErrNo := LineOpen(FLineApp, FDev, @FLine, FVersion, 0, 0,
- LINECALLPRIVILEGE_NONE, FMediaMode, nil); // added FMediaMode 14 Jan 98
- case ErrNo of
- 0: begin
- S := 'Line is open'; // success so drop through
- FPort := GetPortHandle; // added 18 Jan 98
- FCommStatusThread.Resume; // start thread
- SetBitMap(Port, green);
- end;
- LINEERR_ALLOCATED: S := 'LINEERR_ALLOCATED';
- LINEERR_BADDEVICEID: S := 'LINEERR_BADDEVICEID';
- LINEERR_INCOMPATIBLEAPIVERSION: S :=
- 'LINEERR_INCOMPATIBLEAPIVERSION';
- LINEERR_INCOMPATIBLEEXTVERSION: S :=
- 'LINEERR_INCOMPATIBLEEXTVERSION';
- LINEERR_INVALAPPHANDLE: S := 'LINEERR_INVALAPPHANDLE';
- LINEERR_INVALMEDIAMODE: S := 'LINEERR_INVALMEDIAMODE';
- LINEERR_INVALPOINTER: S := 'LINEERR_INVALPOINTER';
- LINEERR_INVALPRIVSELECT: S := 'LINEERR_INVALPRIVSELECT';
- LINEERR_NODEVICE: S := 'LINEERR_NODEVICE';
- LINEERR_LINEMAPPERFAILED: S := 'LINEERR_LINEMAPPERFAILED';
- LINEERR_NODRIVER: S := 'LINEERR_NODRIVER';
- LINEERR_NOMEM: S := 'LINEERR_NOMEM';
- LINEERR_OPERATIONFAILED: S := 'LINEERR_OPERATIONFAILED';
- LINEERR_RESOURCEUNAVAIL: S := 'LINEERR_RESOURCEUNAVAIL';
- LINEERR_STRUCTURETOOSMALL: S := 'LINEERR_STRUCTURETOOSMALL';
- LINEERR_UNINITIALIZED: S := 'LINEERR_UNINITIALIZED';
- LINEERR_REINIT: S := 'LINEERR_REINIT';
- LINEERR_OPERATIONUNAVAIL: S := 'LINEERR_OPERATIONUNAVAIL';
- else
- S := 'LineOpen returned an unknown value of ' + IntToStr(ErrNo);
- end;
- Memo.Lines.Add('LineOpen reports: ' + S);
- if (ErrNo <> 0) then
- Exit
- else
- FLineOpen := true;
-
- // now place the call
- ErrNo := LineMakeCall(FLine, @FHCall, PChar(ePhoneNum.Text), FCountryCode,
- @FLineCallParams);
- case ErrNo of
- 0: begin
- S := 'LineMakeCall succeeded'; // success
- // added 11 jan 98
- // =====================================================================
- end;
- LINEERR_ADDRESSBLOCKED: S := 'LINEERR_ADDRESSBLOCKED';
- LINEERR_BEARERMODEUNAVAIL: S := 'LINEERR_BEARERMODEUNAVAIL';
- LINEERR_CALLUNAVAIL: S := 'LINEERR_CALLUNAVAIL';
- LINEERR_DIALBILLING: S := 'LINEERR_DIALBILLING';
- LINEERR_DIALDIALTONE: S := 'LINEERR_DIALDIALTONE';
- LINEERR_DIALPROMPT: S := 'LINEERR_DIALPROMPT';
- LINEERR_DIALQUIET: S := 'LINEERR_DIALQUIET';
- LINEERR_INUSE: S := 'LINEERR_INUSE';
- LINEERR_INVALADDRESS: S := 'LINEERR_INVALADDRESS';
- LINEERR_INVALADDRESSID: S := 'LINEERR_INVALADDRESSID';
- LINEERR_INVALADDRESSMODE: S := 'LINEERR_INVALADDRESSMODE';
- LINEERR_INVALBEARERMODE: S := 'LINEERR_INVALBEARERMODE';
- LINEERR_INVALCALLPARAMS: S := 'LINEERR_INVALCALLPARAMS';
- LINEERR_INVALCOUNTRYCODE: S := 'LINEERR_INVALCOUNTRYCODE';
- LINEERR_INVALLINEHANDLE: S := 'LINEERR_INVALLINEHANDLE';
- LINEERR_INVALLINESTATE: S := 'LINEERR_INVALLINESTATE';
- LINEERR_INVALMEDIAMODE: S := 'LINEERR_INVALMEDIAMODE';
- LINEERR_INVALPARAM: S := 'LINEERR_INVALPARAM';
- LINEERR_INVALPOINTER: S := 'LINEERR_INVALPOINTER';
- LINEERR_INVALRATE: S := 'LINEERR_INVALRATE';
- LINEERR_NOMEM: S := 'LINEERR_NOMEM';
- LINEERR_OPERATIONFAILED: S := 'LINEERR_OPERATIONFAILED';
- LINEERR_OPERATIONUNAVAIL: S := 'LINEERR_OPERATIONUNAVAIL';
- LINEERR_RATEUNAVAIL: S := 'LINEERR_RATEUNAVAIL';
- LINEERR_RESOURCEUNAVAIL: S := 'LINEERR_RESOURCEUNAVAIL';
- LINEERR_STRUCTURETOOSMALL: S := 'LINEERR_STRUCTURETOOSMALL';
- LINEERR_UNINITIALIZED: S := 'LINEERR_UNINITIALIZED';
- LINEERR_USERUSERINFOTOOBIG: S := 'LINEERR_USERUSERINFOTOOBIG';
- else
- S := 'LineMakeCall returned an unknown value (' + IntToStr(ErrNo) + ')';
- end;
- Memo.Lines.Add('LineMakeCall reports: ' + S);
- end;
-
- function TForm1.ShutdownCallManager: boolean;
- var
- S: string;
- begin
- Result := false;
- case LineShutdown(FLineApp) of
- 0: begin
- S := 'success!';
- { LineShutDown performs the equivalent of LineClose
- so set the line flag to false }
- FLineOpen := false;
- btnHangup.Enabled := false; // disable the hangup button
- btnDial.Enabled := true; // enable the dial button
- Result := true;
- // added 11 jan 98
- ModemOff;
- FCommStatusThread.Terminate;
- // =====================================================================
- end;
- LINEERR_INVALAPPHANDLE: S := 'LINEERR_INVALAPPHANDLE';
- LINEERR_NOMEM: S := 'LINEERR_NOMEM';
- LINEERR_UNINITIALIZED: S := 'LINEERR_UNINITIALIZED';
- LINEERR_RESOURCEUNAVAIL: S := 'LINEERR_RESOURCEUNAVAIL';
- else
- S := 'Unknown value';
- end;
- Memo.Lines.Add('LineShutDown reports: ' + S);
- end;
-
- procedure TForm1.EnumerateDevices;
- var
- i, rc: integer;
- AllocSize: Integer;
- LineDevCaps: LPLINEDEVCAPS; // a pointer of TLineDevCaps type
- begin
- AllocSize := SizeOf(TLINEDEVCAPS);// + 512;
- for i := 0 to FNumDevs - 1 do begin
- LineDevCaps := AllocMem(AllocSize); // This will also fill with zeroes
- try
- // Get dev caps
- LineDevCaps^.dwTotalSize := AllocSize;
- rc := LineGetDevCaps(FLineApp, i, FVersion, 0, LineDevCaps);
- if (LineDevCaps^.dwNeededSize > LineDevCaps^.dwTotalSize) then begin
- // Buffer too small; reallocate and try again
- AllocSize := LineDevCaps^.dwNeededSize;
- ReallocMem(LineDevCaps, AllocSize);
- LineDevCaps^.dwTotalSize := AllocSize;
- rc := LineGetDevCaps(FLineApp, i, FVersion, 0, LineDevCaps);
- end;
- TapiCheck(rc); // Raises exception if rc indicates a line error
- // Extract line name
- if (LineDevCaps^.dwStringFormat = STRINGFORMAT_ASCII) then
- cboxDevices.Items.Add(RecordGetStr(LineDevCaps^,
- @LineDevCaps^.dwLineNameSize))
- else
- cboxDevices.Items.Add('Invalid string format');
- finally
- FreeMem(LineDevCaps);
- end;
- end;
- end;
-
- procedure TForm1.cboxDevicesChange(Sender: TObject);
- begin
- FDev := cboxDevices.ItemIndex;
- StatusBar.Caption := cboxDevices.Text;
- end;
-
- procedure TForm1.cbLineMapperClick(Sender: TObject);
- begin
- cboxDevices.Enabled := not cbLineMapper.Checked;
- if cbLineMapper.Checked then
- FDev := 0
- else
- FDev := cboxDevices.ItemIndex;
- end;
-
- procedure TForm1.ModemOff;
- // sets panel to show all modem lights off
- begin
- SetBitMap(RI, off);
- SetBitMap(CD, off);
- SetBitMap(RD, off);
- SetBitMap(DSR, off);
- SetBitMap(DTR, off);
- SetBitMap(CTS, off);
- SetBitMap(Port, off);
- end;
-
- procedure TForm1.cboxMediaModeChange(Sender: TObject);
- begin
- case cboxMediaMode.ItemIndex of
- 0: FMediaMode := LINEMEDIAMODE_UNKNOWN;
- 1: FMediaMode := LINEMEDIAMODE_INTERACTIVEVOICE;
- 2: FMediaMode := LINEMEDIAMODE_AUTOMATEDVOICE;
- 3: FMediaMode := LINEMEDIAMODE_DATAMODEM;
- 4: FMediaMode := LINEMEDIAMODE_G3FAX;
- 5: FMediaMode := LINEMEDIAMODE_TDD;
- 6: FMediaMode := LINEMEDIAMODE_G4FAX;
- 7: FMediaMode := LINEMEDIAMODE_DIGITALDATA;
- 8: FMediaMode := LINEMEDIAMODE_TELETEX;
- 9: FMediaMode := LINEMEDIAMODE_VIDEOTEX;
- 10: FMediaMode := LINEMEDIAMODE_TELEX;
- 11: FMediaMode := LINEMEDIAMODE_MIXED;
- 12: FMediaMode := LINEMEDIAMODE_ADSI;
- 13: FMediaMode := LINEMEDIAMODE_VOICEVIEW;
- else
- FMediaMode := LINEMEDIAMODE_INTERACTIVEVOICE; // safety valve
- end;
- FLineCallParams.dwMediaMode := FMediaMode;
- end;
-
- procedure TForm1.cboxBearerModeChange(Sender: TObject);
- begin
- case cboxBearerMode.ItemIndex of
- 0: FBearerMode := LINEBEARERMODE_VOICE;
- 1: FBearerMode := LINEBEARERMODE_SPEECH;
- 2: FBearerMode := LINEBEARERMODE_MULTIUSE;
- 3: FBearerMode := LINEBEARERMODE_DATA;
- 4: FBearerMode := LINEBEARERMODE_ALTSPEECHDATA;
- 5: FBearerMode := LINEBEARERMODE_NONCALLSIGNALING;
- 6: FBearerMode := LINEBEARERMODE_PASSTHROUGH;
- else
- FBearerMode := LINEBEARERMODE_SPEECH; // safety valve
- end;
- FLineCallParams.dwBearerMode := FBearerMode;
- end;
-
- procedure TForm1.SetBitmap(Image: TImage; Index: integer);
- var
- Bmp: TBitMap;
- begin
- Bmp := TBitMap.Create;
- try
- ImageList.GetBitMap(Index, Bmp);
- Image.Picture.Bitmap := Bmp;
- finally
- Bmp.Free;
- end;
- end;
-
- function TForm1.GetPortHandle : THandle;
- { code courtesy of Keith Anderson, Keith@PureScience.com
- This code returns the port handle required to pass to SetCommMask,
- GetCommModemStatus and any other low level comm functions }
- type
- LPPort = ^TPort;
- TPort = record
- VarString: TVarString;
- hComm: THandle;
- szDeviceName: array [1..1] of Char;
- end;
- var
- Port: LPPort;
- PortSize: LongInt;
- FError: longint;
- begin
- result := 0;
- if not fLineOpen then exit;
- PortSize := sizeof(TPort);
- GetMem(Port, PortSize);
- Port^.VarString.dwTotalSize := PortSize;
- try
- repeat
- FError := lineGetID(FLine, 0, FHCall, LINECALLSELECT_LINE,
- lpVarString(Port), 'comm');
- if FError < 0 then exit;
- if (Port^.VarString.dwNeededSize > Port^.VarString.dwTotalSize)
- then begin
- PortSize := Port^.VarString.dwNeededSize;
- FreeMem(Port);
- GetMem(Port, PortSize);
- Port^.VarString.dwTotalSize := PortSize;
- FError := -1;
- end;
- until FError = 0;
- Result := Port^.hComm;
- finally
- FreeMem(Port);
- end;
- end;
-
- // Added by Alan 19 April 1998
- procedure TForm1.ShowLineTranslateDialog(Sender: TObject);
- var
- TapiResult : word;
- TempNumber : string;
- begin
- TempNumber := '+1' + Copy(ePhoneNum.Text, 2, Length(ePhoneNum.Text)-1);
- if FDev<0 then
- TapiResult := lineTranslateDialogA(FLineApp, 0, ver, Application.Handle,
- LPCStr(TempNumber))
- else
- TapiResult := lineTranslateDialogA(FLineAPP, FDev, ver, Application.Handle,
- LPCStr(TempNumber));
- if TapiResult<>0 then
- Application.MessageBox('Could not show Line Translate Dialog Box',
- 'Error Opening Line Translate Dialog', MB_OK + MB_ICONERROR)
- else
- lineTranslateAddress(FLineAPP, FDev, ver, FCanonicalPhNum, 0,
- FLineTranslateOptions, lpTranslateOutput);
- end;
-
- procedure TForm1.btnDialingPropertiesClick(Sender: TObject);
- begin
- ShowLineTranslateDialog(Sender);
- end;
-
- end.
-